package com.satan.juc.demo6;

public class FinalReferenceEscapeDemo {
    private final int a;
    private FinalReferenceEscapeDemo referenceDemo;

    public FinalReferenceEscapeDemo() {
        a = 1;  //1
        referenceDemo = this; //2
    }

    public void writer() {
        new FinalReferenceEscapeDemo();
    }

    public void reader() {
        if (referenceDemo != null) {  //3
            int temp = referenceDemo.a; //4
            System.out.println(temp);
        }
    }

    public static void main(String[] args) {
            FinalReferenceEscapeDemo demo = new FinalReferenceEscapeDemo();
            Thread thread1 = new Thread(demo::writer);
            Thread thread2 = new Thread(demo::reader);
            thread1.start();
            thread2.start();

    }
}